package com.exp.bookhouse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exp.bookhouse.pojo.Role;
import com.exp.bookhouse.pojo.MyUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper extends BaseMapper<MyUser> {

    @Update("update tb_user set login_user=#{loginUser}, user_name=#{userName}, phone=#{phone}, address=#{address}, email=#{email}, update_time=#{updateTime} where id = #{id}")
    int updateUser(MyUser myUser);

    @Update("update tb_user set head_image = #{headImage} where id = #{id}")
    int updateHeadImage(@Param("id") Long userId, @Param("headImage") String fullUrl);

    IPage<MyUser> queryUserByIdByPage(IPage<MyUser> iPage, @Param("id") Long id);

    @Select("select *from tb_role where id in (select role_id from tb_user_role where user_id = #{userId})")
    List<Role> queryRoles(Long userId);

    @Select("select *from tb_role where id not in (select role_id from tb_user_role where user_id = #{userId})")
    List<Role> queryOtherRoles(Long userId);

    @Insert("insert into tb_user_role (user_id, role_id) values(#{userId},#{roleId})")
    void saveUserRole(@Param("userId") Long userId, @Param("roleId") Long id);

    @Delete("delete from tb_user_role where user_id = #{id}")
    void deleteUserRole(Long id);

    @Select("select * from tb_user")
    List<MyUser> queryAllUser();


}
